#!/usr/bin/perl 
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
use Cwd;

my $xml = new XML::Simple;
my $data = $xml->XMLin(".repo/manifest.xml");
my $new_data = add_revision($data);
 
sub add_revision {
  my $hashref = shift;
  my $oldpwd  = getcwd;
 
  while ( my ($key, $value) = each(%{%$hashref->{'project'}})) {
    my $var;
    chdir $value->{'path'} or die "Cannot open the directory";
 
    $var =`git log -n 1 --pretty=format:%H`;
 
    $value->{'revision'} = $var;
   # while
 
  chdir $oldpwd;
}
  return $hashref;
} # add_revision
 
my $output = $xml->XMLout($new_data, RootName=>'manifest', XMLDecl => 1);
open (MYFILE, '>>.repo/manifests/pinned_manifest.xml' ) or die "Unable to open file";
print MYFILE $output . "\n";
close (MYFILE);
